class_name PlayerAirState
extends GameplayStateMachine

@onready var player: Player = $"../../"


func _on_setup() -> void:
	add_transition("AnyState", ConditionStateTransition.new("UpState", func(): return player.velocity.y < 0, func(): pass))
	add_transition("AnyState", ConditionStateTransition.new("DownState", func(): return player.velocity.y >= 0, func(): pass))


func _on_update(delta: float) -> void:
	var run_speed = player.get_attribute("run_speed").current_value
	var walk_speed = player.get_attribute("walk_speed").current_value
	
	var movement_speed = run_speed if player.input_handler.is_action_double_click_started_any(["move_left", "move_right"]) else walk_speed
	var movement_input := player.input_handler.get_axis("move_left", "move_right")
	player.velocity.x = movement_input * movement_speed * delta
	
	if movement_input * player.face_direction < 0:
		player.flip()
